//
//  YCCachedObject.swift
//  YCNetworking
//
//  Created by YC on 2017/3/6.
//  Copyright © 2017年 YC. All rights reserved. mail:yangchong364@qq.com
//

import UIKit

class YCCachedObject: NSObject {
    private(set) var content: Data? {
        didSet {
            self.lastUpdateTime = Date(timeIntervalSinceNow: 0)
        }
    }
    private(set) var lastUpdateTime: Date!
    
    var isOutdated: Bool {
        get {
            let timeInterval = Date().timeIntervalSince(self.lastUpdateTime)
            
            return timeInterval > kYCCacheOutdateTimeSeconds;
        }
    }
    var isEmpty: Bool {
        get {
            return self.content == nil
        }
    }
    
    override init() {
        
    }
    
    init(with content: Data) {
        self.content = content
    }
    
    func update(content: Data) {
        self.content = content
    }
    
}
